/*******************************************************************************
 * Copyright (c) 2012-2017 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.plugin.nodejsdbg.ide.configuration;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * The implementation of {@link NodeJsDebuggerConfigurationPageView}.
 *
 * @author Anatolii Bazko
 */
public class NodeJsDebuggerConfigurationPageViewImpl implements NodeJsDebuggerConfigurationPageView {

    private static final NodeJsDebugConfigurationPageViewImplUiBinder UI_BINDER =
            GWT.create(NodeJsDebugConfigurationPageViewImplUiBinder.class);

    private final FlowPanel rootElement;

    @UiField
    TextBox scriptPath;

    private ActionDelegate delegate;

    public NodeJsDebuggerConfigurationPageViewImpl() {
        rootElement = UI_BINDER.createAndBindUi(this);
    }

    @Override
    public void setDelegate(ActionDelegate delegate) {
        this.delegate = delegate;
    }

    @Override
    public Widget asWidget() {
        return rootElement;
    }

    @Override
    public String getScriptPath() {
        return scriptPath.getValue();
    }

    @Override
    public void setScriptPath(String path) {
        this.scriptPath.setValue(path);
    }

    @UiHandler({"scriptPath"})
    void onScriptPathKeyUp(KeyUpEvent event) {
        delegate.onScriptPathChanged();
    }

    interface NodeJsDebugConfigurationPageViewImplUiBinder extends UiBinder<FlowPanel, NodeJsDebuggerConfigurationPageViewImpl> {
    }
}
